package com.xigege.netty.inboundHandlerAndOutboundHandler.client;

import com.xigege.netty.inboundHandlerAndOutboundHandler.coder.MyByteToLongDecoder;
import com.xigege.netty.inboundHandlerAndOutboundHandler.coder.MyLongToByteEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

public class MyClientInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        //出站，从pipeline尾开始走，，
        // 会先调用MyClientHandler，再调用MyLongToByteEncoder

        //加入出站的handler 对数据进行一个编码
        pipeline.addLast(new MyLongToByteEncoder());

        //添加一个入站的解码器
        pipeline.addLast(new MyByteToLongDecoder());

        //加入自定义的handler,处理业务 入站
        pipeline.addLast(new MyClientHandler());
    }
}
